package com.lyw.factory;

import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.ScheduledFuture;
import java.util.concurrent.TimeUnit;

/**
 * @author lyw
 * @Date 2023/2/18-下午3:47
 */
public class TimerTaskPoolFactory implements TimerTaskFactory {

    private final ScheduledExecutorService pool;

    public TimerTaskPoolFactory(ScheduledExecutorService pool) {
        this.pool = pool;
    }

    @Override
    public ScheduledFuture<?> createTimerTask(Runnable timerTask, final long delay, final long step, final TimeUnit unit) {
        return pool.scheduleAtFixedRate(timerTask, delay, step, unit);
    }

    @Override
    public void execute(Runnable runnable) {
        pool.execute(runnable);
    }
}